
//引入axios  http
import http from "@/utils/http/index";

//请求的参数类型
interface AptQuery{
  current: number|string,
  size:number|string,
  provinceId?:number|string,
  cityId?:number|string,
  districtId?:number|string
}
//data
interface AptData<T>{
  current: number|string,
  size:number|string,
  total: number|string,
  pages: number|string,
  records: T[]
}
//records的内部类型
 // 添加修改和详情共用
 // 分页查询 | 查询详情  | 保存修改
 interface ApartmentData {
  id?: number | string
  name: string
  introduction: string
  districtId: number | string
  districtName?: string
  cityId: number | string
  cityName?: string
  provinceId: number | string
  provinceName?: string
  addressDetail: string
  latitude?: number | string
  longitude?: number | string
  phone: string
  isRelease?: string | number | boolean
  totalRoomCount?: number
  freeRoomCount?: number
  // 	公寓配套id
  facilityInfoIds?: number[]
  // 	公寓配套信息
  facilityInfoList?: []
  // 	公寓标签id
  labelIds?: number[]
  // 公寓标签信息
  labelInfoList?: []
  // // 	公寓杂费值id
  feeValueIds?: number[]
  // // 	公寓杂费值信息
  feeValueVoList?: []
  // 图片信息 上传和修改详情的图片详情不同
  graphVoList?:
    {
        url: string
        name: number
    }[]
    | []
}

let aparmentListQuery = (params:AptQuery)=>{
  return http.get<AptData<ApartmentData>>("/admin/apartment/pageItem",params);
} 


//删除公寓的api
let aparmentRemove = (id:number|string)=>{
  return http.delete(`/admin/apartment/removeById?id=${id}`);
}


//保存或者更新公寓api
let apartmentSaveOrUpdate = (apartment:ApartmentData)=>{
    return http.post("/admin/apartment/saveOrUpdate",apartment);
}


//根据id查询公寓详情
let apartmentDetail = (id:number|string)=>{
  return http.get<ApartmentData>(`/admin/apartment/getDetailById?id=${id}`)
}

export {
  type AptQuery, //查询条件的数据类型
  type AptData , //分页查询的返回结果类型
  type ApartmentData , //分页records的具体类型
  aparmentListQuery,
  aparmentRemove,
  apartmentSaveOrUpdate,
  apartmentDetail
}